#include "../maindef.h"
#include "CSkillAffect.h"

#if 0
int CSkillAffect::InitByAffCfg(CSkillAffCfgData& stCfgData, CSkillEffCfg& stSkillEffCfg)
{
    if (!stCfgData.HasCfg())
    {
        return ERROR_SKILL_AFF_EMPTY_CFG;
    }

    _bIsValid = stCfgData._bIsValid;
    _bIsToEnemy = stCfgData._bIsToEnemy;
    _bIsPhy = stCfgData._bIsPhy;
    _ucTargetType = stCfgData._ucTargetType;
    _ucTargetStru = stCfgData._ucTargetStru;
    _uiID = stCfgData._uiID;
    _iMaxAtkDistance = stCfgData._iMaxAtkDistance;
    _iRecommendDistance = stCfgData._iRecommendDistance;
    _iEffectRange = stCfgData._iEffectRange;
    _iSkillAtkValue = stCfgData._iSkillAtkValue;

    _astSkillEff.Clear();

    CSkillEffect stEffect;
    for (int i = 0; i < stCfgData._auiSkillEffIDs.Size(); ++i)
    {
        if (stCfgData._auiSkillEffIDs[i] > 0)
        {
            int iIndex = stSkillEffCfg.FindConfig(stCfgData._auiSkillEffIDs[i]);
            if (iIndex < 0)
            {
                continue;
            }
            CSkillEffCfgData& stEffCfgData = stSkillEffCfg.GetConfig(iIndex);

            stEffect.Clear();

            int iRet = stEffect.InitByEffCfg(stEffCfgData);
            CT_RETURN(iRet);

            iRet = _astSkillEff.AddOneItem(stEffect);
            if (iRet < 0)
            {
                return iRet;
            }
        }
    }

    return 0;
}
#endif

int CSkillAffect::GetSwimEffect(bool& bHasSwimEffect, CSkillEffect& stSwimEffect)
{
    for (int i = 0; i < _astSkillEff.Size(); ++i)
    {
        if (_astSkillEff[i].IsSwim())
        {
            bHasSwimEffect = true;
            stSwimEffect = _astSkillEff[i];
            return 0;
        }
    }

    bHasSwimEffect = false;
    return 0;
}

int CSkillAffect::GetHitBackEffect(bool& bHasHitBackEffect, CSkillEffect& stHitBackEffect)
{
    for (int i = 0; i < _astSkillEff.Size(); ++i)
    {
        if (_astSkillEff[i].IsHitBack())
        {
            bHasHitBackEffect = true;
            stHitBackEffect = _astSkillEff[i];
            return 0;
        }
    }

    bHasHitBackEffect = false;
    return 0;
}

int CSkillAffect::GetPullEffect(bool& bHasPullEffect, CSkillEffect& stPullEffect)
{
    for (int i = 0; i < _astSkillEff.Size(); ++i)
    {
        if (_astSkillEff[i].IsPull())
        {
            bHasPullEffect = true;
            stPullEffect = _astSkillEff[i];
            return 0;
        }
    }

    bHasPullEffect = false;
    return 0;
}

void CSkillAffect::DumpSkillAffectInfo()
{

    CT_BATTLE(("%-18s = %d", "是否生效", _bIsValid));
    CT_BATTLE(("%-18s = %d", "对敌技能", _bIsToEnemy));
    CT_BATTLE(("%-18s = %d", "1:物攻 0魔攻", _bIsPhy));
    CT_BATTLE(("%-18s = %d", "目标类型", _ucTargetType));
    CT_BATTLE(("%-18s = %d", "目标结构", _ucTargetStru));
    CT_BATTLE(("%-18s = %u", "ID", _uiID));
    CT_BATTLE(("%-18s = %d", "最大攻击距离", _iMaxAtkDistance));
    CT_BATTLE(("%-18s = %d", "推荐攻击距离", _iRecommendDistance));
    CT_BATTLE(("%-18s = %d", "波及目标2的范围", _iEffectRange));
    CT_BATTLE(("%-18s = %d", "技能系数", _iSkillAtkValue));

    CT_BATTLE(("技能附带效果数量(%d)", _astSkillEff.Size()));
    for (int i = 0; i < _astSkillEff.Size(); ++i)
    {
        CT_BATTLE(("第(%d)个效果基本信息：", i+1));
        _astSkillEff[i].DumpSkillEffectInfo();
    }
}

